﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Data.SqlClient;

namespace RLZY
{
    public partial class FormGZBH : Form
    {
        public FormGZBH()
        {
            InitializeComponent();
        }
        private static FormGZBH childFromInstanc;
        static log4net.ILog LOG = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        public String userID;
        public String 权限;


        public static FormGZBH ChildFromInstanc
        {
            get
            {
                if (childFromInstanc == null || childFromInstanc.IsDisposed)
                //判断childFromInstanc是否有值，不为null或者窗体释放（当你将子窗体关了的时候）为childFromInstanc赋值
                {
                    childFromInstanc = new FormGZBH();
                }
                return childFromInstanc;
                //返回的childFromInstanc（子窗体存在时返回的是null,关闭了（IsDisposed为true）或者第一次打开子窗体返回一个ChildForm实例）
            }
        }

        private void FormGZBH_Load(object sender, EventArgs e)
        {
            this.Date0 = DateTime.Now.AddDays((double)(0 - DateTime.Now.Day + 1));
            this.Date2 = DateTime.Now.AddDays((double)(0 - DateTime.Now.Day + 32));
            try
            {
                BLL.userpassword bllpwd = new BLL.userpassword();
                Model.userpassword model = bllpwd.GetModel(Convert.ToInt32(others.UserHelper.UserID));
                权限 = model.备注;
            }
            catch (Exception ex) { LOG.Error(ex); }
        }


        public DateTime Date0 { get; set; }

        public DateTime Date2 { get; set; }
        public bool ISSafe()
        {
            others.safe safe = new others.safe();
            SqlDataReader dr = safe.GetGZSafe(this.dtpDate.Text);
            if (dr.Read())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!ISSafe())
            {
                others.safe safe = new others.safe();
                String date = Date0.ToString("yyyy-MM-dd");
                String date2 = Date2.ToString("yyyy-MM-dd");
                if (safe.GZOpreation(权限, date, date2) > 0)
                {
                    MessageBox.Show("保护及本月初始化完毕");

                }
                else
                {
                    MessageBox.Show("初始化过程发生错误！");
                }

            }
            else
            {
                MessageBox.Show("本月已做保护及初始化，不要再做。");
 
            }

        }

        
    }
}
